package com.vaccine.service.impl;

import cn.hutool.core.util.IdUtil;
import com.vaccine.entity.VaccineOrder;
import com.vaccine.mapper.VaccineOrderMapper;
import com.vaccine.service.VaccineOrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class VaccineOrderServiceImpl implements VaccineOrderService {
    @Autowired
    private VaccineOrderMapper vaccineOrderMapper;

    @Override
    @Transactional
    public void inserVaccineOrder(VaccineOrder vaccineOrder) {
        try{
            String orderNo = IdUtil.getSnowflake().nextIdStr();
            vaccineOrder.setOrderNo(orderNo);
            vaccineOrder.setStatus(0); //未审核
            vaccineOrder.setDeleteFlag(0);
            vaccineOrderMapper.insert(vaccineOrder);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public VaccineOrder selectByUserId(Integer userId) {
        QueryWrapper<VaccineOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("delete_flag",0);
        return vaccineOrderMapper.selectOne(queryWrapper);
    }

    @Override
    @Transactional
    public Integer updateStatus(Integer id, Integer status) {
        return vaccineOrderMapper.updateStatus(id,status);
    }


}
